<template>
  <div class="journal-view">
    <ComplexTable
      :columns="columns"
      :list="logData.records"
      :total="Number(logData.total)"
      :page="Number(logData.current)"
      :limit="Number(logData.size)"
      @pagination="pagination"
    />
  </div>
</template>

<script>
import ComplexTable from '@/components/ComplexTable'
import { loginlog } from '@/api/user'
export default {
  name: 'Journal',
  components: { ComplexTable },

  data() {
    return {
      logData: {
        current: 1,
        records: [],
        size: 0,
        total: 0,
        totalPage: 1
      }, // 日志数据
      listQuery: {
        userName: this.$store.state.user.name
      }
    }
  },

  computed: {
    columns() {
      return [
        {
          label: '时间',
          prop: 'accessTime'
        },
        {
          label: 'IP',
          prop: 'ipaddr'
        },
        {
          label: '地区',
          prop: 'addr'
        },
        {
          label: '账号',
          prop: 'userName'
        }
      ]
    }
  },

  created() {
    this.getlogList()
  },

  methods: {
    // 获取日志列表
    getlogList() {
      loginlog(this.listQuery).then(res => {
        this.logData = res
      })
    },

    // 表格切换分页
    pagination(data) {
      this.listQuery = { ...this.listQuery, ...data }
      this.getlogList()
    }
  }
}
</script>

<style lang="scss">
@import './index';
</style>
